<?php

class CustomerController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function showAction()
    {
        $customer = new Application_Model_Dao_CustomerMapper();
        $this->view->entries = $customer->fetchAll();
    }

    public function addAction() {
    	// action body
        $request = $this->getRequest();
        $form = new Application_Form_Customer();
        if($this->getRequest()->isPost())
        {
        	if ($form->isValid($request->getPost())) {
        		$customer = new Application_Model_BusiInfo_Customer($form->getValues());
        		$mapper  = new Application_Model_Dao_CustomerMapper();
        		$mapper->save($customer);
        		return $this->_helper->redirector('show');
        	}
        }
        $this->view->form = $form;
    	
    }
    
    public function editAction() {
     	// action body
        $request = $this->getRequest();
        $customerId = $this->getRequest()->getParam('customerId');
        $mapper  = new Application_Model_Dao_CustomerMapper();
        $customer = $mapper->find($customerId);
        $form = new Application_Form_Customer();
        $form->populate(array('id' 	=> $customer->get_id(),
        						'name' => $customer->get_name(),
        						'taxId' => $customer->get_taxId(),
        						'address' => $customer->get_address(),
        						'phone' => $customer->get_phone(),
        						'bank' => $customer->get_bank(),
        						'account' => $customer->get_account(),
        						
        ));
       
        if($this->getRequest()->isPost())
        {
        	if ($form->isValid($request->getPost())) {
        		$customer = new Application_Model_BusiInfo_Customer($form->getValues());
        		$mapper->save($customer);
        		return $this->_helper->redirector('show');
        	}
        }
        $this->view->form = $form;
    	
    }
    
    
    public function deleteAction() {
    	$customerId = $this->getRequest()->getParam('customerId');
    	$mapper = new Application_Model_Dao_CustomerMapper();
    	$mapper->delete($customerId);
    	return $this->_helper->redirector('show');
    }

}

